﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TDDConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            CBRadio cbradio = new CBRadio(new Watt(4));
            CellPhone cellphone = new CellPhone(new Decibel(27));
            WattDBCalculator wattdb = new WattDBCalculator();
            string choice = "";
            string customlevel = "";
            string customunit = "";
            PowerUnit custompower = null;
            Decibel result = null;
            Watt originalpower = null;

            Console.WriteLine("Welcome to RF Loss Estimator!");

            do
            {
                Console.WriteLine("\nSelect RF Type transmitting: ");
                Console.WriteLine("1. CB Radio (4 W typical)");
                Console.WriteLine("2. Cell Phone (27 dBm typical)");
                Console.WriteLine("3. Custom RF signal");
                Console.WriteLine("q - quit");

                choice = Console.ReadLine();
                if (choice == "q") break;
                if (choice == "3")
                {
                    Console.WriteLine("Enter power level:");
                    customlevel = Console.ReadLine();
                    Console.WriteLine("Enter unit (W or dBm)");
                    customunit = Console.ReadLine();
                    if (customunit.Contains('W'))
                        custompower = new Watt(Convert.ToDouble(customlevel));
                    else
                        custompower = new Decibel(Convert.ToDouble(customlevel));
                }
                Console.WriteLine("Enter detected level (dBm): ");
                string meas = Console.ReadLine();
                double measDouble = Convert.ToDouble(meas);
                Decibel measdB = new Decibel(measDouble);

                if (choice == "1"){
                    result = new Decibel(wattdb.dBLoss(cbradio.wattPower, measdB).Level);
                    originalpower = cbradio.wattPower;
                }
                if (choice == "2")
                {
                    result = new Decibel(wattdb.dBLoss(cellphone.dBPower, measdB).Level);
                    originalpower = wattdb.DBmtoWatt(cellphone.dBPower);
                }
                if (choice == "3"){
                    result = new Decibel(wattdb.dBLoss(custompower, measdB).Level);
                    if (custompower.Unit == "Watt(s)")
                        originalpower = (Watt)custompower;
                    else
                        originalpower = wattdb.DBmtoWatt((Decibel)custompower);
                }
                
                Watt inwatts = wattdb.WattAfterGain(originalpower, result);
                Console.WriteLine("\n{0} dBm loss from {1} W is also {2} W\n", 
                    Math.Round(result.Level, 2), Math.Round(originalpower.Level, 7), Math.Round(inwatts.Level, 7));
            } while (choice != "q");
            //Console.ReadKey();
        }
    }
}
